package com.scuec.groupfive.controller;
//数据概述-用户增长趋势折线图
import com.scuec.groupfive.dto.UserGrowthDTO;
import com.scuec.groupfive.service.UserGrowthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//数据概述-用户增长趋势折线图
import java.util.List;

@RestController
@RequestMapping("/api/analytics/user-growth")
@CrossOrigin
public class UserGrowthController {

    private final UserGrowthService userGrowthService;

    @Autowired
    public UserGrowthController(UserGrowthService userGrowthService) {
        this.userGrowthService = userGrowthService;
    }

    @GetMapping("/daily")
    public List<UserGrowthDTO> getDailyUserGrowth() {
        return userGrowthService.getDailyUserGrowth();
    }

    @GetMapping("/weekly")
    public List<UserGrowthDTO> getWeeklyUserGrowth() {
        return userGrowthService.getWeeklyUserGrowth();
    }

    @GetMapping("/monthly")
    public List<UserGrowthDTO> getMonthlyUserGrowth() {
        List<UserGrowthDTO> result = userGrowthService.getMonthlyUserGrowth();
        // 调试输出
        result.forEach(dto -> System.out.println(
                "Date: " + dto.getDate() +
                        ", Count: " + dto.getCount() +
                        ", GrowthRate: " + dto.getGrowthRate()
        ));
        return result;
    }

    @GetMapping("/yearly")
    public List<UserGrowthDTO> getYearlyUserGrowth() {
        return userGrowthService.getYearlyUserGrowth();
    }
}